package com.kancy.vip.pattern.template.dao;

import com.kancy.vip.pattern.template.JdbcTemplate;
import com.kancy.vip.pattern.template.RowHander;
import com.kancy.vip.pattern.template.User;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

/**
 * @author kancy
 * @date 2019/3/17 17:26
 */
public class User2Dao {

	JdbcTemplate jdbcTemplate = new JdbcTemplate(){};

	public List queryAllUser() throws SQLException {
		String sql = "select * from t_user";
		List<User> list = jdbcTemplate.executeQuery(sql, null, new RowHander<User>() {
			@Override
			public User processRow(ResultSet rs, int i) {
				User user = new User();
				try {
					user.setPassword(rs.getString("password"));
					user.setUserName(rs.getString("username"));
				} catch (SQLException e) {
					e.printStackTrace();
				}
				return user;
			}
		});
		return list;
	}
}
